<template>
	<view class="container" >
		<view class="status_bar">
			<view style="margin-left: 3%;" @tap="goBack()"><u-icon name="arrow-leftward" size='24' /></view>
			<view style="margin-left: -50upx; font-weight: bold;">{{type=="nickname"?"修改个人昵称":"修改个人介绍"}}</view>
			<view></view>
			</u-icon>
		</view>


		<view class="shop-box" v-if="type=='nickname'">
			<u--input v-model="value1" placeholder="请输入内容" height=200 border="none" clearable></u--input>
		</view>
		<view class="shop-box" v-else>
			<u--textarea v-model="value2" placeholder="请输入内容" height=200 border="none" clearable></u--textarea>
		</view>
		<view class="btn-box" @tap="handleUserUpdate()"  v-if="type=='nickname'">确定</u-button></view>
		<view class="btn-box" @tap="handleUserUpdate1()"  v-else>确定</u-button></view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				startX: 0, // 触摸开始的X坐标
				endX: 0, // 触摸结束的X坐标
				threshold: 50, // 设置滑动多少距离后触发返回
				value1: '',
				value2: '',
				type: '',
			}
		},
		onLoad(props) {
			console.log(props.type, "props")
			this.type = props.type
			//this.getDetail()
		},
		methods: {
			goBack() {
				uni.navigateBack({
					delta: 1
				});
			},
			
			
			logout() {
				
				// uni.clearStorageSync()
				uni.MBSocketProvider.closeLocalSocket();
				uni.setStorageSync('loginInfo', {});
				uni.setStorageSync('token', '')
				uni.setStorageSync('user_uid', '')
				uni.setStorageSync('userId', '')
				uni.setStorageSync('user_level', '')
				uni.setStorageSync('nickname', '')
				uni.setStorageSync('user_avatar_file_name', '')
				uni.setStorageSync('loginInfoArr', []);
				this.toPage('/pages/login')
			},
			showEdit() {
				this.groupName = this.group.name
				this.$refs.edit.open()
			},
			cancelEdit() {
				this.$refs.edit.close()
			},
			editAction() {
				if (this.$validate.isNull(this.groupName)) return
				this.$util.loading('保存中')
				uni.request({
					method: 'POST',
					url: this.$api.updateGroupName,
					data: {
						groupId: this.groupId,
						userId: this.userId,
						name: this.groupName
					},
					header: this.$util.getHeader(),
					success: res => {
						uni.hideLoading()
						this.$util.toast(res.data.msg)
						if (!res.data.code) {
							this.$refs.edit.close()
							this.group.name = this.groupName
							uni.setStorageSync('groupName', this.groupName)
						}
					},
					fail: res => {
						uni.hideLoading()
						this.$util.toast('保存失败')
					}
				})
			},
			// 上传头像
			uploadFace() {
				uni.chooseImage({
					count: 1,
					success: chooseRes => {
						const tempFilePaths = chooseRes.tempFilePaths

						this.$util.loading('上传中')
						tempFilePaths.forEach(temp => {
							uni.uploadFile({
								url: this.$api.uploadUserFace,
								filePath: temp,
								formData: {
									groupId: this.groupId,
									userId: this.userId
								},
								name: 'file',
								header: this.$util.getHeader(),
								success: uploadRes => {
									uni.hideLoading()
									if (uploadRes.data.code) return
									let data = JSON.parse(uploadRes.data)
									this.user.face = this.$api.staticPath + data.data
									uni.setStorageSync('userFace', this.user.face)
								}
							})
						})
					}
				})
			},
			handleUserUpdate() {
				uni.request({
					url: this.$api.baseUrl + '/api/user/update',
					header: {
						'content-type': 'application/json'
					},
					data: {
						user_uid: uni.getStorageSync('user_uid'),
						nickname: this.value1,
					},
					method: 'POST',
					success: res => {
						console.log(res, 'res');
						// uni.hideLoading()
						if (res.data.code == 0) {
							// uni.navigateBack();

							
							this.$util.toast(res.data.message)
							uni.navigateBack();
						}
						console.log(this.list);
						// this.list = res.data;
					},
					fail: res => {
						console.log(res);
					}

				})
			},
			handleUserUpdate1() {
				uni.request({
					url: this.$api.baseUrl + '/api/user/update',
					header: {
						'content-type': 'application/json'
					},
					data: {
						user_uid: uni.getStorageSync('user_uid'),
						user_desc: this.value2,
					},
					method: 'POST',
					success: res => {
						console.log(res, 'res');
						// uni.hideLoading()
						if (res.data.code == 0) {
							// uni.navigateBack();
			
							this.$util.toast(res.data.message)
							uni.navigateBack();
						}
						console.log(this.list);
						// this.list = res.data;
					},
					fail: res => {
						console.log(res);
					}
			
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		width: 100%;
		height: 100%;
	}

	.status_bar {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-top: 50upx;
	}

	.status_bar,
	.head {
		background-color: #fff;
		height: 160upx;

		.face {
			width: 160upx;
			height: 160upx;
			border-radius: 10upx;
		}

		.info-name {
			font-size: 40upx;
			font-weight: bold;
		}

		.info-num {
			// width: 56upx;
			padding: 2upx 30upx;
			background: #f0f4f7;
			border-radius: 30upx;
			margin-top: 21upx;
		}

		.copybtns {
			color: #4457a4;
			margin-top: 21upx;
		}
	}


	.shop-box {
		width: 92%;
		height: 36%;
		margin-left: 4%;
		background-color: #f8f9fb;
		margin-top: 20upx;
		border-radius: 20upx;
		padding: 10upx 30upx;
		color: #2e2e2e;
		font-weight: 300;

		image {
			width: 70upx;
			height: 70upx;
			padding: 10upx 28upx 0upx 10upx;

		}

		::v-deep.u-textarea[data-v-81cd9d32],
		.uni-textarea-textarea {
			background-color: #f8f9fb;
		}

		::v-deep.u-input__content__clear {
			background-color: #1a76f1;
		}
	}

	.btn-box {
		width: 92%;
		margin-left: 4%;
		position: absolute;
		bottom: 80upx;
		background: #1a76f1;
		color: #fff;
		text-align: center;
		height: 80upx;
		line-height: 80upx;
		border-radius: 20upx;
		// ::v-deepuni-scroll-view,
		// uni-swiper,
		// uni-swiper-item,
		// uni-view,
		// uni-text,
		// uni-input,
		// uni-textarea {
		// 	color: #fff;
		// }

		// ::v-deep.u-button--square[data-v-3bf2dba7] {
		// 	border-radius: 18upx;
		// }
	}
</style>